package me.hys.service.doctor.impl;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import me.hys.base.PageQuery;
import me.hys.bo.doctor.DiagnoseBo;
import me.hys.dao.doctor.IDiagnoseMapper;
import me.hys.entity.doctor.DiagnoseEntity;
import me.hys.service.doctor.IDiagnoseManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Author: @author HYS . <br>
 * Date: 2015-9-26 上午1:42:21 . <br>
 * Function: 问诊
 */
@Service
@Transactional
class DiagnoseManagerImpl implements IDiagnoseManager {
	@Autowired
	private IDiagnoseMapper diagnoseMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see me.hys.base.IBaseManager#delete(java.lang.String)
	 */
	@Override
	public void delete(String id) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see me.hys.base.IBaseManager#findByCond(java.util.Map)
	 */
	@Override
	public List<DiagnoseEntity> findByCond(Map<String, Object> cond) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see me.hys.base.IBaseManager#findById(java.lang.String)
	 */
	@Override
	public DiagnoseEntity findById(String id) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see me.hys.base.IBaseManager#findPage(me.hys.base.PageQuery)
	 */
	@Override
	public PageQuery<DiagnoseEntity> findPage(PageQuery<DiagnoseEntity> page) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * me.hys.service.doctor.IDiagnoseManager#findPageBo(me.hys.base.PageQuery)
	 */
	@Override
	public PageQuery<DiagnoseBo> findPageBo(PageQuery<DiagnoseBo> page) {
		page.setList(diagnoseMapper.findAllBo(page.getCondition()));
		page.setTotal(diagnoseMapper.findAllBoCount(page.getCondition()));
		// 总页数
		int size = (int) Math.ceil(page.getTotal() * 1.0f / page.getLimit());
		page.setSize(size);
		return page;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see me.hys.base.IBaseManager#saveOrUpdate(java.lang.Object)
	 */
	@Override
	public int saveOrUpdate(DiagnoseEntity entity) {
		if (entity.getId() > 0) {
			return diagnoseMapper.update(entity);
		} else {
			entity.setCreateTime(new Timestamp(System.currentTimeMillis()));
			diagnoseMapper.save(entity);
			return entity.getId();
		}
	}
}
